﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using CdmDeviceHealthMvc.Models;
using SnShared.Models;

namespace CdmDeviceHealthMvc.Controllers
{
    public class RevokedSoftwarePackagesController : ApiController
    {
        private CdmDataCtx db = CdmDataCtx.CreateDbContext();

        // GET: api/RevokedSoftwarePackages
        public IQueryable<SoftwarePackage> GetSoftwarePackages()
        {
            return db.SoftwarePackages.Include("Files").Where(o => o.Revoked);
        }

        // GET: api/RevokedSoftwarePackages/5
        [ResponseType(typeof(SoftwarePackage))]
        public IHttpActionResult GetSoftwarePackage(int id)
        {
            SoftwarePackage softwarePackage = db.SoftwarePackages.Find(id);
            if (softwarePackage == null || !softwarePackage.Revoked)
            {
                return NotFound();
            }

            return Ok(softwarePackage);
        }


        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }

        private bool SoftwarePackageExists(int id)
        {
            return db.SoftwarePackages.Count(e => e.Id == id) > 0;
        }
    }
}